package edu.sctu.liangyuxiang.day20150628;

import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by user20 on 2015/6/28.
 */
public class GetJson {

    public String getJson(String path,String param)throws Exception{
        PrintWriter out = null;

        URL url = new URL(path);
        URLConnection urlConnection = url.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);

        out = new PrintWriter(urlConnection.getOutputStream());
        out.print(param);
        out.flush();

        InputStream inputStream = urlConnection.getInputStream();

        String string = "";
        int count;
        byte[] buffer = new byte[1024];

        while ((count = inputStream.read(buffer))!=-1){
            string+= new String(buffer,0,count,"utf-8");
        }
        inputStream.close();
        return string;
    }

}
